package impl;

import Service.BusLineService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.example.demo.BusLine;
import com.example.demo.BusLineMapper;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class BusLineServiceImpl implements BusLineService {
    private final BusLineMapper busLineMapper;

    public BusLineServiceImpl(BusLineMapper busLineMapper) {
        this.busLineMapper = busLineMapper;
    }

    @Override
    public void addBusLine(BusLine busLine) {
        busLineMapper.insert(busLine);
    }

    @Override
    public void updateBusLine(BusLine busLine) {
        busLineMapper.updateById(busLine);
    }

    @Override
    public void deleteBusLine(Long id) {
        busLineMapper.deleteById(id);
    }

    @Override
    public BusLine getBusLineById(Long id) {
        return busLineMapper.selectById(id);
    }

    @Override
    public List<BusLine> getAllBusLines() {
        return busLineMapper.selectList(null);
    }

    @Override
    public List<BusLine> getBusLinesByName(String name) {
        QueryWrapper<BusLine> queryWrapper = new QueryWrapper<>();
        queryWrapper.like("name", name);
        return busLineMapper.selectList(queryWrapper);
    }

    @Override
    public List<BusLine> getBusLinesByRouteNumber(String routeNumber) {
        QueryWrapper<BusLine> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("route_number", routeNumber);
        return busLineMapper.selectList(queryWrapper);
    }
}